package graphics;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.util.*;




public class Particle {
	int posx, posy, spdx, spdy;
	int lifetime;
	int particleSize = 10000;
	String imageName;
	static Random rnd = new Random();
	int imageId;
	
	public Particle(int x, int y){
		posx=x;
		posy=y;
		spdx=0;
		spdy=0;
		lifetime=100;
		setImage("smoke5.png");
	}
	
	public Particle(int x, int y, int dx, int dy){
		posx=x;
		posy=y;
		spdx=dx+rnd.nextInt(1200)-600;
		spdy=dy+rnd.nextInt(1200)-600;
		lifetime = 90+rnd.nextInt(100);
		setImage("smoke5.png");
	}
	
	public void nextFrame(List<Particle> pList){
		lifetime--;
		if(isDead())
			pList.remove(this);
		posx = posx + spdx;
		posy = posy + spdy;
		//spdx = spdx*99/100;
		//spdy = spdy*99/100-5;
		//spdy=spdy-4;
		//particleSize += 2;
	}
	
	public boolean isDead(){
		return (lifetime <= 0);
	}
	
	public void paint(Point screenOffset, int zoomDivider, Graphics g){
		//g.setColor(new Color(255, 255, 255, lifetime%250));
		//g.setColor(new Color(255, 255, 255));
		//g.drawLine((posx-screenOffset.x)/zoomDivider, (posy-screenOffset.y)/zoomDivider, (posx-screenOffset.x)/zoomDivider, (posy-screenOffset.y)/zoomDivider);
		//g.fillOval((posx-particleSize/2-screenOffset.x)/zoomDivider, (posy-particleSize/2-screenOffset.y)/zoomDivider, (particleSize)/zoomDivider, (particleSize)/zoomDivider);
		
		ImageHandler.getInstance().drawImage((posx-particleSize/2-screenOffset.x)/zoomDivider,
				(posy-particleSize/2-screenOffset.y)/zoomDivider,
				(particleSize)/zoomDivider, (particleSize)/zoomDivider,
				imageId, g);
	}
	public void setImage(String imageName){
		this.imageName = imageName;
		imageId = ImageHandler.getInstance().getIdOfImage(imageName);
	}
}
